define(['layer','md5'],function(layer,md5){
	return{
		init:function(){
            $(".loginBtn").click(function(){
                Login();
            });
            $("body").keypress(function(event){
                if(event.which === 13) {
                    Login();
                }
            })
		}
	}
	function Login() {
        var phone = $.trim($("input[name='phone']").val()),
            passWord = $.trim($("input[name='password']").val());
        if(phone.length>1 && passWord.length>1){
            $.ajax({
                url:"/loginController/loginCheck",
                dataType:"json",
                type:"post",
                data:{
                    "loginName":phone,
                    "password":hex_md5(passWord)
                },
                success:function(result){
                    if(result.code == 10001){
                        window.location.href = "admin"
                    }else {
                        layer.msg(result.msg,{icon:2});
                    }
                }
            })
        }else{
            layer.msg('请输入正确的手机号或密码！',{icon:2});
        }
    }
})